﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Demo.Services.Contracts.DTO.Infos;
using System.Data;
using Demo.CommonBase.Logging;
using Demo.CommonBase.Exceptions;
using System.Reflection;

namespace Demo.Services.Integration.DAO.IntegrationComponents.Mappings
{
    public class DemoDAOMapping
    {
        public static IList<ContactInfo> GetContatctMapping(DataSet ds)
        {
            IList<ContactInfo> result;
            try
            {
                //Logger.Info();
                DataTable dt = ds.Tables[0];

                result = (from contact in dt.AsEnumerable()
                  select new ContactInfo 
                  {
                      Title = contact.Field<string>("Title"),
                      FirsName = contact.Field<string>("FirstName"),
                      LastName = contact.Field<string>("LastName"),
                      Phone = contact.Field<string>("Phone"),
                      EmailAdrres = contact.Field<string>("EmailAddress"),

                  }).ToList();
            }
            catch(Exception ex)
            {
                Logger.Error(ex);
                throw new UnhandledException(MethodInfo.GetCurrentMethod(), ex);
            }

            return result;
        }
    }
}
